<?php
tsLoad('/core/CoreLib/AbstractMysqlPage.class.php');
class SysPhotoPage extends AbstractMysqlPage {
	/* 
	 * 取得总的行数
     */
    protected function calTotalRows ()
    {
        global $mysqlTools;
        $userId = $_SESSION['userInfo']['userId'];
        $condition = $mysqlTools->check_input($this->condition);
        
        $sqlCore = "
            SELECT
                count(*) as totalCount
            FROM
            	sys_photo sp
        ";
        
        $where = "
          WHERE
          sp.userId = 1000000000000154
          AND sp.photoAlbumId = $condition[albumId]
          and sp.photoState =1     
        ";
        
        //时间条件
        if(!empty($condition['photoCreateTimeStart']))
            $where.= ' and sp.photoCreateDate>='.$condition['photoCreateTimeStart'];
        //时间条件
        if(!empty($condition['photoCreateTimeEnd']))
            $where.= ' and sp.photoCreateDate<='.$condition['photoCreateTimeEnd'];
        //关键字查询
        if(!empty($condition['keyWord']))
            $where.= ' and sp.photoTitle like \'%'.$condition['keyWord'].'%\'';
        
        $sql = $sqlCore.$where;
        //总记录数
        $totalRows = $mysqlTools->selectSql($sql)[0]['totalCount'];
        
        return $totalRows;
    }

	/* 
     *取得数据集合
     */
    protected function getList ($sRowNo, $pageRows)
    {
        global $mysqlTools;
        $userId = $_SESSION['userInfo']['userId'];
        $condition = $mysqlTools->check_input($this->condition);
        
        $sqlCore = "
            SELECT
                sp.photoId,
            	sp.photoTitle,
            	sp.photoName,
            	sp.userId,
            	sp.photoAlbumId,
            	sp.photoUrl,
            	sp.photoCreateDate,
            	sp.photoState,
            	sp.photoWidth,
            	sp.photoHeight,
            	sp.photoSize
            FROM
            	sys_photo sp
        ";
        
        $where = "
            WHERE
            	sp.userId = 1000000000000154
            AND sp.photoAlbumId = $condition[albumId]    
            and sp.photoState =1   
        ";
        
        //时间条件
        if(!empty($condition['photoCreateTimeStart']))
            $where.= ' and sp.photoCreateDate>='.$condition['photoCreateTimeStart'];
        //时间条件
        if(!empty($condition['photoCreateTimeEnd']))
            $where.= ' and sp.photoCreateDate<='.$condition['photoCreateTimeEnd'];
        //关键字查询
        if(!empty($condition['keyWord']))
            $where.= ' and sp.photoTitle like \'%'.$condition['keyWord'].'%\'';
        
        $order = ' order by sp.photoCreateDate desc';
        //排序条件
        if(!empty($condition['sortName']) && !empty($condition['sortType']))
            $order = " order by sp.$condition[sortName] $condition[sortType]";
        
        $limit = " limit $sRowNo,$pageRows";
        $sql = $sqlCore.$where.$order.$limit;
        //查询用户相册信息分页
        $list = $mysqlTools->selectSql($sql);
        
        //关闭数据库连接
        
        return $list;
    }

}	

?>